package org.yzh.scheduler.model.entity;

import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;
import org.yzh.scheduler.component.annotations.Cron;
import org.yzh.scheduler.model.enums.ContentType;
import org.yzh.scheduler.model.enums.HttpMethod;
import org.yzh.scheduler.model.vo.BasicScheduleJob;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

public class ScheduleJobDO extends BasicScheduleJob implements Serializable {

    @ApiModelProperty("id")
    private Integer id;

    @ApiModelProperty("任务名称(接口名)")
    private String jobName;

    @ApiModelProperty("任务组(系统名)")
    private String jobGroup;

    @ApiModelProperty("是否禁用")
    private Boolean disable;

    @Cron
    @Length(max = 120)
    @ApiModelProperty("cron表达式")
    private String cronExpression;

    @Length(max = 250)
    @ApiModelProperty("任务描述")
    private String description;

    @NotNull
    @ApiModelProperty("HttpMethod")
    private HttpMethod method;

    @URL
    @Length(max = 250)
    @ApiModelProperty("HttpURL")
    private String url;

    @NotNull
    @ApiModelProperty("HttpContentType")
    private ContentType contentType;

    @ApiModelProperty("HttpParameters")
    private String parameters;

    @ApiModelProperty("修改时间")
    private LocalDateTime updateTime;

    @ApiModelProperty("创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty("最近一次运行日志")
    private JobLogDO jobLog;

    public ScheduleJobDO() {
    }

    public ScheduleJobDO(String jobName, String jobGroup) {
        this.jobName = jobName;
        this.jobGroup = jobGroup;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getJobGroup() {
        return jobGroup;
    }

    public void setJobGroup(String jobGroup) {
        this.jobGroup = jobGroup;
    }

    public String getJobName() {
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public Boolean getDisable() {
        return disable;
    }

    public void setDisable(Boolean disable) {
        this.disable = disable;
    }

    public String getCronExpression() {
        return cronExpression;
    }

    public void setCronExpression(String cronExpression) {
        this.cronExpression = cronExpression;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public HttpMethod getMethod() {
        return method;
    }

    public void setMethod(HttpMethod method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public ContentType getContentType() {
        return contentType;
    }

    public void setContentType(ContentType contentType) {
        this.contentType = contentType;
    }

    public String getParameters() {
        return parameters;
    }

    public void setParameters(String parameters) {
        this.parameters = parameters;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public JobLogDO getJobLog() {
        return jobLog;
    }

    public void setJobLog(JobLogDO jobLog) {
        this.jobLog = jobLog;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        ScheduleJobDO other = (ScheduleJobDO) that;
        return (this.getJobGroup() == null ? other.getJobGroup() == null : this.getJobGroup().equals(other.getJobGroup()))
                && (this.getJobName() == null ? other.getJobName() == null : this.getJobName().equals(other.getJobName()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getJobGroup() == null) ? 0 : getJobGroup().hashCode());
        result = prime * result + ((getJobName() == null) ? 0 : getJobName().hashCode());
        return result;
    }
}